package com.dld.protocol.image;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.util.Log;

public class ImageViewFill {

	public static Bitmap fillImageView(String path, int targetwidth,
			int targetHeight) {
		int width = targetwidth;
		int height = targetHeight;
		Options op = new Options();
		op.inJustDecodeBounds = true;
		Bitmap bmp = BitmapFactory.decodeFile(path, op);
		int bmpwidth = op.outWidth;
		int bmpheight = op.outHeight;

		width = width == 0 ? 50 : width;
		height = height == 0 ? 50 : height;

		int scalew = bmpwidth / width + 1;
		int scaleh = bmpheight / height + 1;

		int sample = scalew > scaleh ? scalew : scaleh;
		op = new Options();
		op.inSampleSize = sample;
		bmp = BitmapFactory.decodeFile(path, op);
		return bmp;
	}

}
